<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<title>HTML代码运行器 - Codeasy</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="Codeasy,Code Easy,运行HTML,HTML,HTML代码,执行HTML,提高开发效率,java,代码,开发工具,辅助开发">
<meta http-equiv="description" content="HTML代码运行器">

<script type="text/javascript">
	var userAgent = navigator.userAgent.toLowerCase();
	var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
	var is_moz = (navigator.product == 'Gecko')
			&& userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
	var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera)
			&& userAgent.substr(userAgent.indexOf('msie') + 5, 3);

	function isUndefined(variable) {
		return typeof variable == 'undefined' ? true : false;
	}

	function runCode(objName) {
		var obj = document.getElementsByName(objName)[0];
		if (obj == null || isUndefined(obj)) {
			obj = document.getElementById(objName);
		}
		var winname = window.open('', "_blank", '');
		winname.document.open('text/html', 'replace');
		winname.opener = null // 防止代码对原页面修改
		winname.document.write(obj.value);
		winname.document.close();
	}
	function saveCode(objName) {
		var obj = document.getElementsByName(objName)[0];
		if (obj == null || isUndefined(obj)) {
			obj = document.getElementById(objName);
		}
		var winname = window.open('', '_blank', 'top=10000');
		winname.document.open('text/html', 'replace');
		winname.document.write(obj.value);
		winname.document.execCommand('saveas', '', 'code.htm');
		winname.close();
	}

	function copyCode(objName) {
		var obj = document.getElementsByName(objName)[0];
		if (obj == null || isUndefined(obj)) {
			obj = document.getElementById(objName);
		}

		if (is_ie && obj.style.display != 'none') {
			var rng = document.body.createTextRange();
			rng.moveToElementText(obj);
			rng.scrollIntoView();
			rng.select();
			rng.execCommand("Copy");
			rng.collapse(false);
		} else {
			alert("遗憾呐，您当前的浏览器不支持此操作，请手动选择文本进行复制吧。");
		}

	}

	function resetCode(objName) {
		var obj = document.getElementsByName(objName)[0];
		if (obj == null || isUndefined(obj)) {
			obj = document.getElementById(objName);
		}
		obj.value = initHTML;
	}

	function cleanCode(objName) {
		var obj = document.getElementsByName(objName)[0];
		if (obj == null || isUndefined(obj)) {
			obj = document.getElementById(objName);
		}
		obj.value = '';
	}

	var initHTML = "";
	function f_onload(objName) {
		var obj = document.getElementsByName(objName)[0];
		if (obj == null || isUndefined(obj)) {
			obj = document.getElementById(objName);
		}
		initHTML = obj.value;
	}
</script>

<style type="text/css">

body{
	text-align:center
}

.ta {
	font-size: 13px;
}

.mainDiv {
    width:900px;margin-left:auto;margin-right:auto;
	margin-top: 0px;
}

.btn {
	margin-top: 20px;
}
</style>

</head>

<body onload="f_onload('runcode1');">
	
	<s:include value="/common/header.jsp"></s:include>

	<div class="mainDiv">
		<table>
			<tr>
				<td colspan="2"><h2>HTML代码运行器</h2></td>
			</tr>
			<tr>
				<td>HTML源码</td>
				<td><textarea style="text-align: left;" cols="120" rows="20" name="runcode1"
						id="runcode1" class="ta" >
					
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

	<!--您可以选择在此快捷实现JS代码-->
	<script type="text/javascript">
		function f_test() {

		}
	</script>

	<!--您可以选择在此快捷实现CSS代码-->
	<style type="text/css">
          
	</style>

	<title>标题</title>
</head>

<body>
	文本框:<input type="text" width="400px" id="testInput1" name="testInput1" />
	<input type="button" onclick="f_test();" value="触发事件的按钮" />
</body>
</html>
					
					</textarea>
					</td>
			</tr>
			<tr>
				<td colspan="2">
				    <div class="btn">
					    <input type="button" onclick="runCode('runcode1');"
						value="运行代码" /> <input type="button"
						onclick="resetCode('runcode1');" value="重置代码" /> <input
						type="button" onclick="cleanCode('runcode1');" value="清空代码" /> <input
						type="button" onclick="copyCode('runcode1');" value="复制代码" /> <input
						type="button" onclick="saveCode('runcode1');" value="保存代码" />
				    </div>
				</td>

			</tr>
		</table>
	</div>
    <s:include value="/common/footer.jsp"></s:include>
</body>
</html>